package cn.cnsuh.剑指offer.q06_从尾到头打印链表;

import java.util.Stack;

public class Main {
}

class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}

class Solution {
    public int[] reversePrint(ListNode head) {
        Stack<Integer> s = new Stack();
        int len = 0;
        while(head!=null){
            s.push(head.val);
            head = head.next;
            len++;
        }
        int[] ans = new int[len];
        for(int i = 0 ; i < len ; i++){
            ans[i] = s.pop();
        }
        return ans;
    }
}
